package com.online.web.shiro.action.user;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.online.web.shiro.biz.user.RoleBiz;
import com.online.web.shiro.dao.user.RoleDao;
import com.online.web.shiro.model.user.RoleInfo;
import com.online.web.shiro.util.lang.JsonUtil;
import com.online.web.shiro.util.lang.PageUtils;

/**
 * 角色管理
 * 
 * @author tongyufu
 *
 */
@RestController
@RequestMapping("/admin/role")
public class RoleAction {

    @Autowired
    private RoleBiz roleBiz;
    @Autowired
    private RoleDao roleDao;

    @RequestMapping("search")
    public String search(@RequestParam Map<String, Object> params) {
        PageUtils.processPage(params);
        return JsonUtil.toPageJson(roleDao.search(params), roleDao.searchTotal(params));
    }

    /**指定用户的权限树*/
    @RequestMapping("queryByUser")
    public List<Map<String, Object>> queryByUser(Integer userId) {
        return roleBiz.queryByUser(userId);
    }

    @RequestMapping("save")
    public String save(RoleInfo roleInfo) {
        return roleBiz.save(roleInfo);
    }

    @RequestMapping("queryById")
    public RoleInfo queryById(Integer id) {
        return roleDao.queryById(id);
    }

    @RequestMapping("delete")
    public String delete(Integer id) {
        return roleBiz.delete(id);
    }

    @RequestMapping("authorization")
    public String authorization(String permissions, Integer roleId) {
        return roleBiz.authorization(permissions, roleId);
    }

}
